using System;
using Science.Mathematics;
using L=Science.Physics.GeneralPhysics;
using M = Science.Mathematics.Calculus;

namespace Serway.Chapter30
{
	/// <summary>
	/// Example07: The Magnetic Force on a Current Segment
	/// Wire 1 in Figure 30.16 is oriented along the y axis and 
	/// carries a steady current I_1. A rectangular loop located 
	/// to the right of the wire and in the xy plane carries a 
	/// current I_2. Find the magnetic force exerted by wire 1 on 
	/// the top wire of length b in the loop, labeled Wire 2 in 
	/// the figure.
	/// </summary>
	public class Example07
	{
		public Example07()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
		private double a = 1.0;
		private double b = 3.0;
		public void Compute()
		{
			L.Vector.FunctionOfPosition faa 
				= new L.Vector.FunctionOfPosition (Bfield);
			L.MagneticField B = new L.MagneticField();
            B.VectorFunctionOfPosition = faa;
			
			L.Line.Parameterization fa 
				= new L.Line.Parameterization(Line);
			L.Line l = new L.Line(fa);
			l.ParameterStartValue = a;
			l.ParameterEndValue = b;
		
			L.ElectricCurrent I = new L.ElectricCurrent();
			I.A = 10.0;

		    L.MagneticForce F = new L.MagneticForce(I,l,B);
			
			result+=Convert.ToString(F.X)+"\r\n"
				+Convert.ToString(F.Y)+"\r\n"
				+Convert.ToString(F.Z)+"\r\n";

			result+=Convert.ToString(I.A/2.0/Math.PI
				*Math.Log(1.0+(b-a)/a))+"\r\n";
		}
		private L.Position Line(double t)
		{
			L.Position xyz = new L.Position();
			xyz.X = t;
			xyz.Y = 0.0;
			xyz.Z = 0.0;
			return xyz;
		}
		private L.Vector Bfield(L.Position r)
		{
			L.Vector B = new L.Vector();
			B.X = 0.0;
			B.Y = 0.0;
			B.Z = -1.0/2.0/Math.PI/r.X;
			return B;
		}
	}
}
